<?php

ob_start();
include_once ('../utilities.php')

?>
<!DOCTYPE html>
<html>
<head>
	<link rel="stylesheet" type="text/css" href="../reset.css">
	<link rel="stylesheet" type="text/css" href="../mainStyle.css">
	<link rel="stylesheet" type="text/css" href="../searchButton.css">
	<title>SHPE</title>
</head>
<body>

	<div id="container">
		<?php

$success = false;
$failed = false;
if (!empty($_POST['email']) && !empty($_POST['password']))
{
    //Used form

    $myuser = $factory->getUserByEmail($_POST['email'], $_POST['password'], false);
    if (!is_null($myuser))
    {
        //serialize user into session variable
        $_SESSION['LoggedIn'] = 1;
        $_SESSION['User'] = serialize($myuser);
        define('IN_PHPBB', true);
        $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../forum/';
        $phpEx = substr(strrchr(__file__, '.'), 1);
        include_once ($phpbb_root_path . 'common.' . $phpEx);
        include_once ($phpbb_root_path . 'includes/functions_display.' . $phpEx);
        $user->session_begin();
        $auth->acl($user->data);
        $user->setup('viewforum');
        $prefix = substr($_POST['email'], 0, strrpos($_POST['email'], '@'));
        $result = $auth->login($prefix, $_POST['password'], 0, 0, 0);
        //var_dump($user);
        /*
        $_SESSION['bb3user'] = serialize($user);
        $_SESSION['auth'] = serialize($auth);
        $_SESSION['IN_PHPBB'] = true;*/

        $success = true;
    } else
    {
        $failed = true;
    }
}
$root = '../';
include_once ('../header.php');

?>
        
		<div id="page-body">
			<?php

if ($success)
{
    echo "<p> You have been successfully logged in. </p>";
} elseif ($failed)
{
    echo "<p> Sorry, your account could not be found. </p>";
} elseif (!empty($_SESSION['LoggedIn']) && !empty($_SESSION['User']))
{

?>

				 <p> You are already logged in.</p>
				 			
				<?php

} else
{

?>
				
			   <h1>Member Login</h1>
				
			   <p>Please either login below, or <a href="../register/">click here to register</a>.</p>
			   <p> You may also register your chapter <a href="../register/chapterregistration/">here</a> first. </p>
				
				<form method="post" action="./" name="loginform" id="loginform">
				<fieldset>
					<label for="email">Email:</label><input type="text" name="email" id="email" /><br />
					<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
					<input type="submit" name="login" id="login" value="Login" />
				</fieldset>
				</form>
					
				<?php

}

?>
		</div>
		
		<?php

include_once ('../footer.php')

?>
	</div>

</body>
</html>